package merge;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class TestIterator {
    public static void main(String[] args) {
        Collection<Student> collection = new ArrayList<>();
        collection.add(new Student("颜林廷", "2班", 90.0));
        collection.add(new Student("yyy", "1班", 80.0));
        collection.add(new Student("ttt", "2班", 85.0));
        collection.add(new Student("tty", "2班", 95.5));

        //        System.out.println(collection);

        // 创建迭代器
        Iterator<Student> iterator = collection.iterator();
        // 可以使用while循环遍历列表
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
//        while (iterator.hasNext()){
//            iterator.next().stu_score= iterator.next().stu_score+10;
//        }
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
        // 也可以使用forEachRemaining带入箭头函数遍历列表
//        iterator.forEachRemaining(x-> System.out.print(x.toUpperCase()));

        // 也可以使用for遍历列表
        System.out.println("学生原成绩：");
        for (Student s : collection) {
            System.out.println(s);
        }

        for (Student s : collection) {
            if (s.s_class == "2班") {
                s.score += 10;
                if (s.score > 100) {s.score = 100.0;}
            }
        }
        System.out.println();
        System.out.println("2班的学生加10分后的结果：");

        for (Student s : collection) {
            System.out.println(s);
        }

        System.out.println();
    }

}
